﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PrzetwarzanieObrazow
{
    public partial class Form1 : Form
    {
        //public List<System.Windows.Forms.ToolStripMenuItem> listGuzikow= new List<ToolStripMenuItem>();
        //public List<List<ToolStripMenuItem>> menuGorny= new List<List<ToolStripMenuItem>>();
        Filtry filtry = new Filtry();
        UnsafeBitmap glownaBitmapa;

        //Lista list guzikow np [Plik-> [Nowy][Otworz]],[Edycja->[a1][a2]]
        public Form1()
        {
            InitializeComponent();
            dynamiczneFiltry();
        }
        void dynamiczneFiltry()
        {
            foreach (Filtr fltr in filtry.getFiltrList())
            {
            filtryToolStripMenuItem.DropDownItems.Add(new ToolStripMenuItem(fltr.ToString(),null, pustyToolStripMenuItem_Click));
            }
             
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                Bitmap tempBitamp = new Bitmap(openFileDialog1.FileName);
                glownaBitmapa = new UnsafeBitmap(tempBitamp);
                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox1.Image = (Image)glownaBitmapa.Bitmap;
                pictureBox1.Refresh();
   
            }
        }

        private void pustyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (glownaBitmapa != null)
            {
                ToolStripMenuItem tsmi = (ToolStripMenuItem)sender;
                foreach (Filtr fltr in filtry.getFiltrList())
                {
                    if (tsmi.Text == fltr.ToString())
                    {
                        glownaBitmapa.LockBitmap();
                        fltr.oblicz(glownaBitmapa);
                        glownaBitmapa.UnlockBitmap();
                        break;
                    }
                }
                pictureBox1.Refresh();
            }
            else
            {
                MessageBox.Show("Brak obrazka!");
            }
        }
    }
}
